public class Test11 {
    public static double power(double base,int e){
        if(base == 0 && e== 0) throw new RuntimeException("invalid");
        //指数为0
        if(e == 0) return 1;
        //指数为1
        if(e == 1) return base;
        //求指数的绝对值
        int exp = e;
        if(exp < 0){
            exp = -exp;
        }
        double res = powerWithUnsigned(base,exp);
        if(e < 0){
            res = 1/res;
        }
        return res;

    }
    public static double powerWithUnsigned(double base,int e){
        if(e == 0) return 0;
        if(e == 1) return 1;
        double res = powerWithUnsigned(base,e>>1);
        res = res*res;
        if(e % 2 !=0) //如果是奇数还需要在×一个base
            res *= base;
        return  res;
    }
    public static void main(String[] args) {

        System.out.println(power(2, -4));
        System.out.println(power(2, 4));
        System.out.println(power(2, 0));
        System.out.println(power(0.0000000000000000000001, -1));
        System.out.println(power(0.0000000000000000000001, 1));
        System.out.println(power(0.0000000000000000000001, 0));
        System.out.println(power(0.0000000000000000000000, 0));
    }
}
